﻿Imports System.Collections.ObjectModel
Imports System.IO

Module Main
    Const MaxPerFile As Integer = 50000

    Sub Main()
        Dim myArgs As ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
        If (myArgs.Count >= 1) Then
            Dim obj As Object = Nothing
            Dim cmd As String = myArgs(0).ToLower

            Dim intTest As Integer = 0
            Dim restart As Boolean = False
            If (myArgs.Count >= 2) Then
                If IsNumeric(myArgs(1)) Then
                    intTest = CInt(myArgs(1))
                ElseIf myArgs(1).ToLower = "restart" Then
                    restart = True
                End If
            End If
           
            If cmd = "delta" Then
                obj = New remax("C:\New_RemaxSitemaps\RemaxSitemaps\Remax_Active_ForSaleProperties_Delta", "sitemapforsalenew", True)
            ElseIf cmd = "active" Then
                obj = New remax("C:\New_RemaxSitemaps\RemaxSitemaps\Remax_Active_ForSaleProperties", "sitemapforsaleproperties", False)
            ElseIf cmd = "all" Then
                obj = New slszip("C:\New_RemaxSitemaps\RemaxSitemaps\RemaxHomeValues", "sitemaphomevalues", False)
            Else
                If (myArgs.Count >= 2) AndAlso Directory.Exists(cmd) Then
                    utils.WriteSiteMapIndex(cmd, myArgs(1))
                End If
            End If

            If Not obj Is Nothing Then
                Console.WindowWidth = 100
                Dim tic As Long = Now.Ticks
                obj.StartProcess(MaxPerFile, intTest, restart)
                Console.ForegroundColor = ConsoleColor.Red
                Console.WriteLine("")
                Console.WriteLine(" " & TimeSpan.FromTicks(Now.Ticks - tic).ToString)
                Console.ForegroundColor = ConsoleColor.Green
            End If
        Else
            ShowHelp()
        End If
    End Sub

    Sub ShowHelp()
        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine("")
        Console.WriteLine("This application creates sitemaps ")
        Console.WriteLine(" No arguments given ")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.Yellow
        Console.WriteLine("We have 3 main groups:")
        Console.WriteLine(" - delta  =  Will generate new active listings")
        Console.WriteLine(" - active =  Will generate all active listings")
        Console.WriteLine(" - all    =  Will generate all properties")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine(" Here are some sample calls ")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.White
        Console.WriteLine(":: Generate only 3 files from the delta")
        Console.WriteLine("sitemaps.exe delta 3")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.Cyan
        Console.WriteLine(":: Generate entire actives")
        Console.WriteLine("sitemaps.exe active")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.White
        Console.WriteLine(":: Rebuild SiteMapsIndex")
        Console.WriteLine("sitemaps.exe C:\mySiteMaps rmxSiteMaps")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.Cyan
        Console.WriteLine(":: Restart the all process from the last file")
        Console.WriteLine("sitemaps.exe all restart")
        Console.WriteLine("")
        Console.WriteLine("")
        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine("Hit ENTER to continue...")
        Console.ReadLine()
    End Sub

End Module
